package io.finer.erp.jeecg.stock.service;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;

import io.finer.erp.jeecg.bas.dto.FqDTO;
import io.finer.erp.jeecg.stock.entity.StkInventory;
import io.finer.erp.jeecg.stock.entity.StkIoBillEntry;

/**
 * @Description: 库存
 * @Author: jeecg-boot
 * @Date:   2020-04-11
 * @Version: V1.0
 */
public interface IStkInventoryService extends IService<StkInventory> {
    void increase(StkIoBillEntry stkIoBillEntry);
    void decrease(StkIoBillEntry stkIoBillEntry);
    void newDecrease(StkIoBillEntry stkIoBillEntry);
    void changeCost(StkIoBillEntry stkIoBillEntry);
    StkInventory getByBatchNoAndX(String batchNo, String materialId, String warehouseId);
    StkInventory getByMaterial(String materialId);
    
    boolean changeStoreInventory(List<String> materialIds);
    
    List<FqDTO> getFqParameter(BigDecimal width, BigDecimal length, String categoryId);
	/**
	 * @Description 根据物料id和仓库id查询实时库存
	 * @param warehouseId
	 * @param materialId
	 * @return
	 * Create at: 2020-11-03 11:18:07
	 * @author: duany
	 * Revision:
	 *    2020-11-03 11:18:07 - first revision by duany
	 *        
	 */
	StkInventory selectByWarehouseAndMaterial(String warehouseId, String materialId);
	List<StkInventory> selectByMaterials(List<String> materialIds);
	/**
	 * @Description 生产入库时计算成本后修改已经入库的成本 以便于后期核算
	 * @param stkIoBillEntry
	 * Create at: 2020-11-04 10:29:40
	 * @author: duany
	 * Revision:
	 *    2020-11-04 10:29:40 - first revision by duany
	 *        
	 */
	public void updateProductInCost(StkIoBillEntry stkIoBillEntry);
	
	/**
	 * @Description 根据物料ID获取最新的物料
	 * @param id
	 * @return
	 * Create at: 2020-11-10 17:38:23
	 * @author: duany
	 * Revision:
	 *    2020-11-10 17:38:23 - first revision by duany
	 *        
	 */
	StkInventory selectLatestByMaterial(String id);
	
	/**
	 * @Description 根据传入的物料ID查询该物料的分类下的所有库存
	 * @param materialId
	 * @return
	 * Create at: 2020-11-17 09:28:29
	 * @author: duany
	 * Revision:
	 *    2020-11-17 09:28:29 - first revision by duany
	 *        
	 */
	List<StkInventory> getInventoryCategoryByMaterialId(String materialId);
	
	/**
	 * @Description 根据传入的物料ID查询该物料的分类下的所有在成品库中的库存
	 * @param materialId
	 * @return
	 * Create at: 2020-11-17 09:55:53
	 * @author: duany
	 * Revision:
	 *    2020-11-17 09:55:53 - first revision by duany
	 *        
	 */
	BigDecimal getCPQtyByMaterialId(String materialId);
	
	/**
	 * @Description 根据传入的物料ID查询该物料的分类下的所有在半成品库及原料库中的库存
	 * @param materialId
	 * @return
	 * Create at: 2020-11-17 09:55:53
	 * @author: duany
	 * Revision:
	 *    2020-11-17 09:55:53 - first revision by duany
	 *        
	 */
	BigDecimal getBCPQtyByMaterialId(String materialId);
	
	/**
	 * @Description 根据传入的分类ID查询该分类下的所有在成品库中的物料库存
	 * @param materialId
	 * @return
	 * Create at: 2020-11-17 09:55:53
	 * @author: duany
	 * Revision:
	 *    2020-11-17 09:55:53 - first revision by duany
	 *        
	 */
	BigDecimal getCPQtyByCategoryId(String categoryId);
	
	/**
	 * @Description 根据传入的分类ID查询该分类下的所有在半成品库及原料库中的物料库存
	 * @param materialId
	 * @return
	 * Create at: 2020-11-17 09:55:53
	 * @author: duany
	 * Revision:
	 *    2020-11-17 09:55:53 - first revision by duany
	 *        
	 */
	BigDecimal getBCPQtyByCategoryId(String categoryId);


	/**
	 * 根据id将数据生成elxe表单。并上传到钉钉发送文件消息通知
	 * @param id
	 * @return
	 */
	boolean upDdFile(String id);
	
	boolean upDdFile(String id, HashSet<String> orderIdSet);
	
	Page<StkInventory> getInventory(IPage<StkInventory> page,@Param("ids")List<String> ids,
			@Param("warehouseId")String warehouseId,@Param("supplierId")String supplierId,
			@Param("isClosed")String isClosed,@Param("batchNoBegin")String batchNoBegin,
			@Param("batchNoEnd")String batchNoEnd,@Param("createTime")String createTime);
	/**
	 * @Description 获得库存数大于0的物料数量
	 * @param materialIds 要查询的物料ID集合
	 * @return 数量
	 * Create at: 2021-04-20 17:09:43
	 * @author: duany
	 * Revision:
	 *    2021-04-20 17:09:43 - first revision by duany
	 *        
	 */
	int countHasInventoryMateiral(List<String> materialIds);

}
